﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Collections.Generic;
using System.Text;
using System.Reflection;
public partial class Controls_SHANGPINSEARCH : System.Web.UI.UserControl
{
    public string p
    {
        set { Hidden1.Value = value; }
    }

    private bool SelectProductConfig
    {
        get
        {
            return new BLL.SYSPARAM().GetSelectProductConfig();
        }
    }

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            TreeBind();
        }
    }

    #region 加载树

    private void TreeBind()
    {
        ///获取电子商务商品属性名称
        Model.SYSPARAM sysparm = new BLL.SYSPARAM().GetModel("002");
        //获取ERP商品属性
        string strSql = "select * from main where id='0'";
        DataSet ds = new BLL.SHANGPIN().GetListBySql(strSql);
        bool isRight = false;
        if (ds != null)
        {
            if (ds.Tables[0].Rows.Count != 0)
            {
                isRight = true;
            }
        }
        foreach (TreeNode tn in TreeView1.Nodes)
        {
            switch (tn.Value)
            {
                case "year":
                    DataTable dt = new BLL.PINPAI().GetYearList().Tables[0];
                    for (int i = 0; i < dt.Rows.Count; i++)
                    {
                        TreeNode ztn = new TreeNode();
                        ztn.Text = dt.Rows[i]["byzd8"].ToString();
                        ztn.Value = dt.Rows[i]["byzd8"].ToString();
                        ztn.ShowCheckBox = true;
                        ztn.SelectAction = TreeNodeSelectAction.None;
                        tn.ChildNodes.Add(ztn);
                    }
                    break;
                case "jijie":
                    List<Model.JIJIE> jj = new BLL.JIJIE().GetAllList();
                    foreach (Model.JIJIE j in jj)
                    {
                        TreeNode ztn2 = new TreeNode();
                        ztn2.Text = j.JJMC;
                        ztn2.Value = j.JJDM;
                        ztn2.ShowCheckBox = true;
                        ztn2.SelectAction = TreeNodeSelectAction.None;
                        tn.ChildNodes.Add(ztn2);
                    }
                    break;
                case "dalei":
                    List<Model.DALEI> dl = new BLL.DALEI().GetAllList();
                    foreach (Model.DALEI d in dl)
                    {
                        TreeNode ztn3 = new TreeNode();
                        ztn3.Text = d.DLMC;
                        ztn3.Value = d.DLDM;
                        ztn3.ShowCheckBox = true;
                        ztn3.SelectAction = TreeNodeSelectAction.None;
                        tn.ChildNodes.Add(ztn3);
                    }
                    break;
                case "pinpai":
                    List<Model.PINPAI> pp = new BLL.PINPAI().GetAllList();
                    foreach (Model.PINPAI p in pp)
                    {
                        TreeNode ztn4 = new TreeNode();
                        ztn4.Text = p.PPMC;
                        ztn4.Value = p.PPDM;
                        ztn4.ShowCheckBox = true;
                        ztn4.SelectAction = TreeNodeSelectAction.None;
                        tn.ChildNodes.Add(ztn4);
                    }
                    break;
                case "1":
                    if (isRight == true)
                    {
                        tn.Text=ds.Tables[0].Rows[0]["FJMC1"].ToString();
                    }
                    List<Model.FJSX1> ff1 = new BLL.FJSX1().GetAllList();
                    foreach (Model.FJSX1 f1 in ff1)
                    {
                        TreeNode ztn5 = new TreeNode();
                        ztn5.Text = f1.SXMC;
                        ztn5.Value = f1.SXDM;
                        ztn5.ShowCheckBox = true;
                        ztn5.SelectAction = TreeNodeSelectAction.None;
                        tn.ChildNodes.Add(ztn5);
                    }
                    break;
                case "2":
                    if (isRight == true)
                    {
                        tn.Text = ds.Tables[0].Rows[0]["FJMC2"].ToString();
                    }
                    List<Model.FJSX2> ff2 = new BLL.FJSX2().GetAllList();
                    foreach (Model.FJSX2 f2 in ff2)
                    {
                        TreeNode ztn6 = new TreeNode();
                        ztn6.Text = f2.SXMC;
                        ztn6.Value = f2.SXDM;
                        ztn6.ShowCheckBox = true;
                        ztn6.SelectAction = TreeNodeSelectAction.None;
                        tn.ChildNodes.Add(ztn6);
                    }
                    break;
                case "3":
                    if (isRight == true)
                    {
                        tn.Text = ds.Tables[0].Rows[0]["FJMC3"].ToString();
                    }
                    List<Model.FJSX3> ff3 = new BLL.FJSX3().GetAllList();
                    foreach (Model.FJSX3 f3 in ff3)
                    {
                        TreeNode ztn7 = new TreeNode();
                        ztn7.Text = f3.SXMC;
                        ztn7.Value = f3.SXDM;
                        ztn7.ShowCheckBox = true;
                        ztn7.SelectAction = TreeNodeSelectAction.None;
                        tn.ChildNodes.Add(ztn7);
                    }
                    break;
                case "4":
                    if (isRight == true)
                    {
                        tn.Text = ds.Tables[0].Rows[0]["FJMC4"].ToString();
                    }
                    List<Model.FJSX4> ff4 = new BLL.FJSX4().GetAllList();
                    foreach (Model.FJSX4 f4 in ff4)
                    {
                        TreeNode ztn8 = new TreeNode();
                        ztn8.Text = f4.SXMC;
                        ztn8.Value = f4.SXDM;
                        ztn8.ShowCheckBox = true;
                        ztn8.SelectAction = TreeNodeSelectAction.None;
                        tn.ChildNodes.Add(ztn8);
                    }
                    break;
                case "5":
                    if (isRight == true)
                    {
                        tn.Text = ds.Tables[0].Rows[0]["FJMC5"].ToString();
                    }
                    List<Model.FJSX5> ff5 = new BLL.FJSX5().GetAllList();
                    foreach (Model.FJSX5 f5 in ff5)
                    {
                        TreeNode ztn9 = new TreeNode();
                        ztn9.Text = f5.SXMC;
                        ztn9.Value = f5.SXDM;
                        ztn9.ShowCheckBox = true;
                        ztn9.SelectAction = TreeNodeSelectAction.None;
                        tn.ChildNodes.Add(ztn9);
                    }
                    break;
                case "6":
                    if (isRight == true)
                    {
                        tn.Text = ds.Tables[0].Rows[0]["FJMC6"].ToString();
                    }
                    List<Model.FJSX6> ff6 = new BLL.FJSX6().GetAllList();
                    foreach (Model.FJSX6 f6 in ff6)
                    {
                        TreeNode ztn10 = new TreeNode();
                        ztn10.Text = f6.SXMC;
                        ztn10.Value = f6.SXDM;
                        ztn10.ShowCheckBox = true;
                        ztn10.SelectAction = TreeNodeSelectAction.None;
                        tn.ChildNodes.Add(ztn10);
                    }
                    break;
                case "7":                   
                    if (sysparm != null)
                    {
                        tn.Text = sysparm.SP_PARAM13.Trim();
                    }
                    List<Model.AUTOPROP1> ff7 = new BLL.AUTOPROP1().GetAllList();
                    foreach (Model.AUTOPROP1 f7 in ff7)
                    {
                        TreeNode ztn11 = new TreeNode();
                        ztn11.Text = f7.AP1_NAME;
                        ztn11.Value = f7.AP1_CODE;
                        ztn11.ShowCheckBox = true;
                        ztn11.SelectAction = TreeNodeSelectAction.None;
                        tn.ChildNodes.Add(ztn11);
                    }
                    break;
                case "8":
                    if (sysparm != null)
                    {
                        tn.Text = sysparm.SP_PARAM14.Trim();
                    }
                    List<Model.AUTOPROP2> ff8 = new BLL.AUTOPROP2().GetAllList();
                    foreach (Model.AUTOPROP2 f8 in ff8)
                    {
                        TreeNode ztn12 = new TreeNode();
                        ztn12.Text = f8.AP2_NAME;
                        ztn12.Value = f8.AP2_CODE;
                        ztn12.ShowCheckBox = true;
                        ztn12.SelectAction = TreeNodeSelectAction.None;
                        tn.ChildNodes.Add(ztn12);
                    }
                    break;
                case "9":
                    if (sysparm != null)
                    {
                        tn.Text = sysparm.SP_PARAM15.Trim();
                    }
                    List<Model.AUTOPROP3> ff9 = new BLL.AUTOPROP3().GetAllList();
                    foreach (Model.AUTOPROP3 f9 in ff9)
                    {
                        TreeNode ztn13 = new TreeNode();
                        ztn13.Text = f9.AP3_NAME;
                        ztn13.Value = f9.AP3_CODE;
                        ztn13.ShowCheckBox = true;
                        ztn13.SelectAction = TreeNodeSelectAction.None;
                        tn.ChildNodes.Add(ztn13);
                    }
                    break;
                case "10":
                    if (sysparm != null)
                    {
                        tn.Text = sysparm.SP_PARAM16.Trim();
                    }
                    List<Model.AUTOPROP4> ff10 = new BLL.AUTOPROP4().GetAllList();
                    foreach (Model.AUTOPROP4 f10 in ff10)
                    {
                        TreeNode ztn14 = new TreeNode();
                        ztn14.Text = f10.AP4_NAME;
                        ztn14.Value = f10.AP4_CODE;
                        ztn14.ShowCheckBox = true;
                        ztn14.SelectAction = TreeNodeSelectAction.None;
                        tn.ChildNodes.Add(ztn14);
                    }
                    break;
                case "11":
                    if (sysparm != null)
                    {
                        tn.Text = sysparm.SP_PARAM17.Trim();
                    }
                    List<Model.AUTOPROP5> ff11 = new BLL.AUTOPROP5().GetAllList();
                    foreach (Model.AUTOPROP5 f11 in ff11)
                    {
                        TreeNode ztn15 = new TreeNode();
                        ztn15.Text = f11.AP5_NAME;
                        ztn15.Value = f11.AP5_CODE;
                        ztn15.ShowCheckBox = true;
                        ztn15.SelectAction = TreeNodeSelectAction.None;
                        tn.ChildNodes.Add(ztn15);
                    }
                    break;
                case "12":
                    if (sysparm != null)
                    {
                        tn.Text = sysparm.SP_PARAM18.Trim();
                    }
                    List<Model.AUTOPROP6> ff12 = new BLL.AUTOPROP6().GetAllList();
                    foreach (Model.AUTOPROP6 f12 in ff12)
                    {
                        TreeNode ztn16 = new TreeNode();
                        ztn16.Text = f12.AP6_NAME;
                        ztn16.Value = f12.AP6_CODE;
                        ztn16.ShowCheckBox = true;
                        ztn16.SelectAction = TreeNodeSelectAction.None;
                        tn.ChildNodes.Add(ztn16);
                    }
                    break;
            }
            tn.SelectAction = TreeNodeSelectAction.None;
            tn.CollapseAll();
        }

    }
    #endregion

    private void Bind()
    {
        if (this.SelectProductConfig)
        {
            string StrSql = "";
            if (TextBox1.Text.Trim() != "")
            {
                if (DropDownList1.SelectedValue == "0")
                {
                    StrSql += " and SPDM like '%" + TextBox1.Text.Trim() + "%' ";
                }
                else if (DropDownList1.SelectedValue == "2")
                {
                    StrSql += " and SPMC like '%" + TextBox1.Text.Trim() + "%' ";
                }
                else if (DropDownList1.SelectedValue == "1")
                {
                    StrSql += " and CA_NAME like '%" + TextBox1.Text.Trim() + "%' ";
                }

            }
            int pageCount, rowCount;
            DataSet ds = new BLL.SHANGPIN().GetSPListSearch("select spdm,spdm+'  '+isnull(CA_NAME,'') as spmc from shangpin left join COMMODITY_AUTO on spdm=CA_CODE where 1=1 " + StrSql);
            ListBox1.DataSource = ds.Tables[0].DefaultView;
            ListBox1.DataTextField = "SPMC";
            ListBox1.DataValueField = "SPDM";
            ListBox1.DataBind();
        }
        else
        {
            string StrSql = "";
            if (TextBox1.Text.Trim() != "")
            {
                if (DropDownList1.SelectedValue == "0")
                {
                    StrSql += " and Shangpin.SPDM like '%" + TextBox1.Text.Trim() + "%' ";
                }
                else if (DropDownList1.SelectedValue == "2")
                {
                    StrSql += " and SPMC like '%" + TextBox1.Text.Trim() + "%' ";
                }
                else if (DropDownList1.SelectedValue == "1")
                {
                    StrSql += " and CA_NAME like '%" + TextBox1.Text.Trim() + "%' ";
                }

            }
            StringBuilder sb = new StringBuilder();
            sb.Append("select ProductUpDown.SPDM,ProductUpDown.SPDM+' '+isnull(CA_NAME,'') as spmc ");
            sb.Append("from ProductUpDown left join COMMODITY_AUTO ");
            sb.Append("ON ProductUpDown.SPDM=COMMODITY_AUTO.CA_CODE LEFT JOIN SHANGPIN ");
            sb.Append("ON ProductUpDown.SPDM=SHANGPIN.SPDM ");
            sb.Append("WHERE ISUP=1 ");
            //int pageCount, rowCount;
            DataSet ds = new BLL.SHANGPIN().GetSPListSearch(sb.ToString() + StrSql + "GROUP BY ProductUpDown.SPDM,SPMC,CA_NAME");
            ListBox1.DataSource = ds.Tables[0].DefaultView;
            ListBox1.DataTextField = "SPMC";
            ListBox1.DataValueField = "SPDM";
            ListBox1.DataBind();
        }

    }
    private void Sbind()
    {
        if (this.SelectProductConfig)
        {
            string sb = "";//where 子句
            string a = " and ( ";
            string b = " ) ";
            #region where条件
            foreach (TreeNode tn in TreeView1.Nodes)
            {
                if (tn.Checked)
                {
                    int l = sb.Length;
                    switch (tn.Value)
                    {
                        case "year":
                            if (tn.ChildNodes.Count > 0)
                            {
                                sb += a;
                                foreach (TreeNode ztn in tn.ChildNodes)
                                {
                                    if (ztn.Checked)
                                    {
                                        sb += " or byzd8='" + ztn.Value + "' ";
                                    }
                                }
                                sb = sb.Remove(l + a.Length, 3);
                                sb += b;
                            }
                            break;
                        case "jijie":
                            if (tn.ChildNodes.Count > 0)
                            {
                                sb += a;
                                foreach (TreeNode ztn in tn.ChildNodes)
                                {
                                    if (ztn.Checked)
                                    {
                                        sb += " or byzd5='" + ztn.Value + "' ";
                                    }
                                }
                                sb = sb.Remove(l + a.Length, 3);
                                sb += b;
                            }
                            break;
                        case "dalei":
                            if (tn.ChildNodes.Count > 0)
                            {
                                sb += a;
                                foreach (TreeNode ztn in tn.ChildNodes)
                                {
                                    if (ztn.Checked)
                                    {
                                        sb += " or byzd4='" + ztn.Value + "' ";
                                    }
                                }
                                sb = sb.Remove(l + a.Length, 3);
                                sb += b;
                            }
                            break;
                        case "pinpai":
                            if (tn.ChildNodes.Count > 0)
                            {
                                sb += a;
                                foreach (TreeNode ztn in tn.ChildNodes)
                                {
                                    if (ztn.Checked)
                                    {
                                        sb += " or byzd3='" + ztn.Value + "' ";
                                    }
                                }
                                sb = sb.Remove(l + a.Length, 3);
                                sb += b;
                            }
                            break;
                        case "1":
                            if (tn.ChildNodes.Count > 0)
                            {
                                sb += a;
                                foreach (TreeNode ztn in tn.ChildNodes)
                                {
                                    if (ztn.Checked)
                                    {
                                        sb += " or fjsx1='" + ztn.Value + "' ";
                                    }
                                }
                                sb = sb.Remove(l + a.Length, 3);
                                sb += b;
                            }
                            break;
                        case "2":
                            if (tn.ChildNodes.Count > 0)
                            {
                                sb += a;
                                foreach (TreeNode ztn in tn.ChildNodes)
                                {
                                    if (ztn.Checked)
                                    {
                                        sb += " or fjsx2='" + ztn.Value + "' ";
                                    }
                                }
                                sb = sb.Remove(l + a.Length, 3);
                                sb += b;
                            }
                            break;
                        case "3":
                            if (tn.ChildNodes.Count > 0)
                            {
                                sb += a;
                                foreach (TreeNode ztn in tn.ChildNodes)
                                {
                                    if (ztn.Checked)
                                    {
                                        sb += " or fjsx3='" + ztn.Value + "' ";
                                    }
                                }
                                sb = sb.Remove(l + a.Length, 3);
                                sb += b;
                            }
                            break;
                        case "4":
                            if (tn.ChildNodes.Count > 0)
                            {
                                sb += a;
                                foreach (TreeNode ztn in tn.ChildNodes)
                                {
                                    if (ztn.Checked)
                                    {
                                        sb += " or fjsx4='" + ztn.Value + "' ";
                                    }
                                }
                                sb = sb.Remove(l + a.Length, 3);
                                sb += b;
                            }
                            break;
                        case "5":
                            if (tn.ChildNodes.Count > 0)
                            {
                                sb += a;
                                foreach (TreeNode ztn in tn.ChildNodes)
                                {
                                    if (ztn.Checked)
                                    {
                                        sb += " or fjsx5='" + ztn.Value + "' ";
                                    }
                                }
                                sb = sb.Remove(l + a.Length, 3);
                                sb += b;
                            }
                            break;
                        case "6":
                            if (tn.ChildNodes.Count > 0)
                            {
                                sb += a;
                                foreach (TreeNode ztn in tn.ChildNodes)
                                {
                                    if (ztn.Checked)
                                    {
                                        sb += " or fjsx6='" + ztn.Value + "' ";
                                    }
                                }
                                sb = sb.Remove(l + a.Length, 3);
                                sb += b;
                            }
                            break;
                        case "7":
                            if (tn.ChildNodes.Count > 0)
                            {
                                sb += a;
                                foreach (TreeNode ztn in tn.ChildNodes)
                                {
                                    if (ztn.Checked)
                                    {
                                        sb += " or CA_AUTOPROP1='" + ztn.Value + "' ";
                                    }
                                }
                                sb = sb.Remove(l + a.Length, 3);
                                sb += b;
                            }
                            break;
                        case "8":
                            if (tn.ChildNodes.Count > 0)
                            {
                                sb += a;
                                foreach (TreeNode ztn in tn.ChildNodes)
                                {
                                    if (ztn.Checked)
                                    {
                                        sb += " or CA_AUTOPROP2='" + ztn.Value + "' ";
                                    }
                                }
                                sb = sb.Remove(l + a.Length, 3);
                                sb += b;
                            }
                            break;
                        case "9":
                            if (tn.ChildNodes.Count > 0)
                            {
                                sb += a;
                                foreach (TreeNode ztn in tn.ChildNodes)
                                {
                                    if (ztn.Checked)
                                    {
                                        sb += " or CA_AUTOPROP3='" + ztn.Value + "' ";
                                    }
                                }
                                sb = sb.Remove(l + a.Length, 3);
                                sb += b;
                            }
                            break;
                        case "10":
                            if (tn.ChildNodes.Count > 0)
                            {
                                sb += a;
                                foreach (TreeNode ztn in tn.ChildNodes)
                                {
                                    if (ztn.Checked)
                                    {
                                        sb += " or CA_AUTOPROP4='" + ztn.Value + "' ";
                                    }
                                }
                                sb = sb.Remove(l + a.Length, 3);
                                sb += b;
                            }
                            break;
                        case "11":
                            if (tn.ChildNodes.Count > 0)
                            {
                                sb += a;
                                foreach (TreeNode ztn in tn.ChildNodes)
                                {
                                    if (ztn.Checked)
                                    {
                                        sb += " or CA_AUTOPROP5='" + ztn.Value + "' ";
                                    }
                                }
                                sb = sb.Remove(l + a.Length, 3);
                                sb += b;
                            }
                            break;
                        case "12":
                            if (tn.ChildNodes.Count > 0)
                            {
                                sb += a;
                                foreach (TreeNode ztn in tn.ChildNodes)
                                {
                                    if (ztn.Checked)
                                    {
                                        sb += " or CA_AUTOPROP6='" + ztn.Value + "' ";
                                    }
                                }
                                sb = sb.Remove(l + a.Length, 3);
                                sb += b;
                            }
                            break;
                    }

                }
            }
            #endregion
            int pageCount, rowCount;
            DataSet ll = new BLL.SHANGPIN().GetListBySql("select spdm,spdm+'  '+isnull(CA_NAME,'') as spmc from shangpin left join COMMODITY_AUTO on spdm=CA_CODE where 1=1 " + sb);
            ListBox1.DataSource = ll.Tables[0].DefaultView;
            ListBox1.DataTextField = "SPMC";
            ListBox1.DataValueField = "SPDM";
            ListBox1.DataBind();
        }
        else
        {
            StringBuilder str = new StringBuilder();
            str.Append("select ProductUpDown.SPDM,ProductUpDown.SPDM+' '+isnull(CA_NAME,'') as spmc ");
            str.Append("from ProductUpDown left join COMMODITY_AUTO ");
            str.Append("ON ProductUpDown.SPDM=COMMODITY_AUTO.CA_CODE LEFT JOIN SHANGPIN ");
            str.Append("ON ProductUpDown.SPDM=SHANGPIN.SPDM ");
            str.Append("WHERE ISUP=1 ");

            string sb = "";//where 子句
            string a = " and ( ";
            string b = " ) ";
            #region where条件
            foreach (TreeNode tn in TreeView1.Nodes)
            {
                if (tn.Checked)
                {
                    int l = sb.Length;
                    switch (tn.Value)
                    {
                        case "year":
                            if (tn.ChildNodes.Count > 0)
                            {
                                sb += a;
                                foreach (TreeNode ztn in tn.ChildNodes)
                                {
                                    if (ztn.Checked)
                                    {
                                        sb += " or SHANGPIN.byzd8='" + ztn.Value + "' ";
                                    }
                                }
                                sb = sb.Remove(l + a.Length, 3);
                                sb += b;
                            }
                            break;
                        case "jijie":
                            if (tn.ChildNodes.Count > 0)
                            {
                                sb += a;
                                foreach (TreeNode ztn in tn.ChildNodes)
                                {
                                    if (ztn.Checked)
                                    {
                                        sb += " or SHANGPIN.byzd5='" + ztn.Value + "' ";
                                    }
                                }
                                sb = sb.Remove(l + a.Length, 3);
                                sb += b;
                            }
                            break;
                        case "dalei":
                            if (tn.ChildNodes.Count > 0)
                            {
                                sb += a;
                                foreach (TreeNode ztn in tn.ChildNodes)
                                {
                                    if (ztn.Checked)
                                    {
                                        sb += " or SHANGPIN.byzd4='" + ztn.Value + "' ";
                                    }
                                }
                                sb = sb.Remove(l + a.Length, 3);
                                sb += b;
                            }
                            break;
                        case "pinpai":
                            if (tn.ChildNodes.Count > 0)
                            {
                                sb += a;
                                foreach (TreeNode ztn in tn.ChildNodes)
                                {
                                    if (ztn.Checked)
                                    {
                                        sb += " or SHANGPIN.byzd3='" + ztn.Value + "' ";
                                    }
                                }
                                sb = sb.Remove(l + a.Length, 3);
                                sb += b;
                            }
                            break;
                        case "1":
                            if (tn.ChildNodes.Count > 0)
                            {
                                sb += a;
                                foreach (TreeNode ztn in tn.ChildNodes)
                                {
                                    if (ztn.Checked)
                                    {
                                        sb += " or SHANGPIN.fjsx1='" + ztn.Value + "' ";
                                    }
                                }
                                sb = sb.Remove(l + a.Length, 3);
                                sb += b;
                            }
                            break;
                        case "2":
                            if (tn.ChildNodes.Count > 0)
                            {
                                sb += a;
                                foreach (TreeNode ztn in tn.ChildNodes)
                                {
                                    if (ztn.Checked)
                                    {
                                        sb += " or SHANGPIN.fjsx2='" + ztn.Value + "' ";
                                    }
                                }
                                sb = sb.Remove(l + a.Length, 3);
                                sb += b;
                            }
                            break;
                        case "3":
                            if (tn.ChildNodes.Count > 0)
                            {
                                sb += a;
                                foreach (TreeNode ztn in tn.ChildNodes)
                                {
                                    if (ztn.Checked)
                                    {
                                        sb += " or SHANGPIN.fjsx3='" + ztn.Value + "' ";
                                    }
                                }
                                sb = sb.Remove(l + a.Length, 3);
                                sb += b;
                            }
                            break;
                        case "4":
                            if (tn.ChildNodes.Count > 0)
                            {
                                sb += a;
                                foreach (TreeNode ztn in tn.ChildNodes)
                                {
                                    if (ztn.Checked)
                                    {
                                        sb += " or SHANGPIN.fjsx4='" + ztn.Value + "' ";
                                    }
                                }
                                sb = sb.Remove(l + a.Length, 3);
                                sb += b;
                            }
                            break;
                        case "5":
                            if (tn.ChildNodes.Count > 0)
                            {
                                sb += a;
                                foreach (TreeNode ztn in tn.ChildNodes)
                                {
                                    if (ztn.Checked)
                                    {
                                        sb += " or SHANGPIN.fjsx5='" + ztn.Value + "' ";
                                    }
                                }
                                sb = sb.Remove(l + a.Length, 3);
                                sb += b;
                            }
                            break;
                        case "6":
                            if (tn.ChildNodes.Count > 0)
                            {
                                sb += a;
                                foreach (TreeNode ztn in tn.ChildNodes)
                                {
                                    if (ztn.Checked)
                                    {
                                        sb += " or SHANGPIN.fjsx6='" + ztn.Value + "' ";
                                    }
                                }
                                sb = sb.Remove(l + a.Length, 3);
                                sb += b;
                            }
                            break;
                        case "7":
                            if (tn.ChildNodes.Count > 0)
                            {
                                sb += a;
                                foreach (TreeNode ztn in tn.ChildNodes)
                                {
                                    if (ztn.Checked)
                                    {
                                        sb += " or CA_AUTOPROP1='" + ztn.Value + "' ";
                                    }
                                }
                                sb = sb.Remove(l + a.Length, 3);
                                sb += b;
                            }
                            break;
                        case "8":
                            if (tn.ChildNodes.Count > 0)
                            {
                                sb += a;
                                foreach (TreeNode ztn in tn.ChildNodes)
                                {
                                    if (ztn.Checked)
                                    {
                                        sb += " or CA_AUTOPROP2='" + ztn.Value + "' ";
                                    }
                                }
                                sb = sb.Remove(l + a.Length, 3);
                                sb += b;
                            }
                            break;
                        case "9":
                            if (tn.ChildNodes.Count > 0)
                            {
                                sb += a;
                                foreach (TreeNode ztn in tn.ChildNodes)
                                {
                                    if (ztn.Checked)
                                    {
                                        sb += " or CA_AUTOPROP3='" + ztn.Value + "' ";
                                    }
                                }
                                sb = sb.Remove(l + a.Length, 3);
                                sb += b;
                            }
                            break;
                        case "10":
                            if (tn.ChildNodes.Count > 0)
                            {
                                sb += a;
                                foreach (TreeNode ztn in tn.ChildNodes)
                                {
                                    if (ztn.Checked)
                                    {
                                        sb += " or CA_AUTOPROP4='" + ztn.Value + "' ";
                                    }
                                }
                                sb = sb.Remove(l + a.Length, 3);
                                sb += b;
                            }
                            break;
                        case "11":
                            if (tn.ChildNodes.Count > 0)
                            {
                                sb += a;
                                foreach (TreeNode ztn in tn.ChildNodes)
                                {
                                    if (ztn.Checked)
                                    {
                                        sb += " or CA_AUTOPROP5='" + ztn.Value + "' ";
                                    }
                                }
                                sb = sb.Remove(l + a.Length, 3);
                                sb += b;
                            }
                            break;
                        case "12":
                            if (tn.ChildNodes.Count > 0)
                            {
                                sb += a;
                                foreach (TreeNode ztn in tn.ChildNodes)
                                {
                                    if (ztn.Checked)
                                    {
                                        sb += " or CA_AUTOPROP6='" + ztn.Value + "' ";
                                    }
                                }
                                sb = sb.Remove(l + a.Length, 3);
                                sb += b;
                            }
                            break;
                    }

                }
            }
            #endregion
            //int pageCount, rowCount;
            DataSet ll = new BLL.SHANGPIN().GetListBySql(str.ToString() + sb + "GROUP BY ProductUpDown.SPDM,SPMC,CA_NAME");
            ListBox1.DataSource = ll.Tables[0].DefaultView;
            ListBox1.DataTextField = "SPMC";
            ListBox1.DataValueField = "SPDM";
            ListBox1.DataBind();
        }
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        Bind();
    }
    protected void Button4_Click(object sender, EventArgs e)
    {
        Sbind();
    }
    protected void Button2_Click(object sender, EventArgs e)
    {

    }
}